package com.delong.util;

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;

public class AliYunOSSUtil {

	private static String SECURITY_KEY = "RQLhCf8ok6VUdzEOblJ36N5SwknRpY";
	private static String ACCESS_KEY = "U6MDPA8PT6ddHH3X";
	private static String END_POINT = "http://oss-cn-hangzhou.aliyuncs.com"; 
	private static String BUCKET_NAME = "dlmarket";

	public static String applyOSS(String key, byte[] data,String contentType) throws FileNotFoundException {
		OSSClient client = new OSSClient(END_POINT, ACCESS_KEY, SECURITY_KEY);
		InputStream content = new ByteArrayInputStream(data);
		ObjectMetadata meta = new ObjectMetadata();
		meta.setContentLength(data.length);
		meta.setContentType(contentType);
		client.putObject(BUCKET_NAME, key, content, meta);
		return "http://" + BUCKET_NAME + ".oss-cn-hangzhou.aliyuncs.com/" + key;
	}

}
